package com.pro.service.imple;

import com.pro.mapper.JsProductMapper;
import com.pro.pojo.*;
import com.pro.service.JsProductService;
import com.pro.utils.RedisCatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author YuQing
 * @date 2022/1/6 19:16
 */
@Service
public class JsProductServiceImple implements JsProductService {
    @Autowired
    private JsProductMapper jsProductMapper;

    //redis缓存
    @Autowired
    private RedisCatch redisCatch;

    /**
     * @author: YuQing
     * @date: 2022/2/27
     * @description: 添加redis缓存
     */
    public List<JsProductCategroy> ifRedisCacheHaveTree(String cacheName){
        List<JsProductCategroy> productCategroy = redisCatch.getCacheList(cacheName);
        if(productCategroy==null || productCategroy.isEmpty()){
            productCategroy = jsProductMapper.getProductTree();
            redisCatch.setCacheList(cacheName,productCategroy);
        }
        return productCategroy;
    }

    @Override
    public List<JsProductCategroy> getProductCategroys() {
        return jsProductMapper.getProductCategroys();
    }

    @Override
    public List<Integer> judgePower(Integer id) {
        return jsProductMapper.judgePower(id);
    }

    @Override
    public List<JsProductCategroy> getProductTree() {
        List<JsProductCategroy> productTree = ifRedisCacheHaveTree("productTree");
        JsProductCategroy productCategroy = new JsProductCategroy();
        productCategroy.setCategroyId(0);
        productCategroy.setParentId(-1);
        productCategroy.setTitle("选择分类类型");
        productTree.add(productCategroy);
        return productTree;
    }

    @Override
    public boolean addZtree(JsProductCategroy productCategroy) {
        redisCatch.deleteObject("productTree");
        return jsProductMapper.addZtree(productCategroy);
    }

    @Override
    public Integer getProductTreeCount(Integer categroyId) {
        return jsProductMapper.getProductTreeCount(categroyId);
    }

    @Override
    public boolean deleteZtree(Integer categroyId) {
        redisCatch.deleteObject("productTree");
        return jsProductMapper.deleteZtree(categroyId);
    }

    @Override
    public boolean updateZtree(String title, Integer categroyId) {
        redisCatch.deleteObject("productTree");
        return jsProductMapper.updateZtree(title, categroyId);
    }

    @Override
    public List<JsProduct> getCheckedProduct(JsProduct product) {
        return jsProductMapper.getCheckedProduct(product);
    }

    @Override
    public List<JsProduct> getProductSearch(JsProduct product) {
        return jsProductMapper.getProductSearch(product);
    }


    @Override
    public List<JsProduct> advancedSearch(JsProduct product) {
        return jsProductMapper.advancedSearch(product);
    }

    @Override
    public JsProduct getProductInformation(Integer type, Integer id) {
        return jsProductMapper.getProductInformation(type, id);
    }
    //修改商品状态
    @Override
    public Boolean updateProductState(JsProduct product) {
        return jsProductMapper.updateProductState(product);
    }
    //查询商品审核详情
    @Override
    public  List<JsCourseRecord> getProductExamine(JsCourseRecord courseRecord) {
        return jsProductMapper.getProductExamine(courseRecord);
    }
    //添加商品操作日志
    @Override
    public Boolean addProductLog(JsLog log) {
        return jsProductMapper.addProductLog(log);
    }
    //修改商品
    @Override
    public Boolean updateProduct(JsProduct product) {
        return jsProductMapper.updateProduct(product);
    }
    //添加历史价格详情
    @Override
    public Boolean addProductJournal(JsCourseJournal courseJournal) {
        return jsProductMapper.addProductJournal(courseJournal);
    }
    //查看商品操作日志
    @Override
    public List<JsLog> getProductLog(JsLog log) {
        return jsProductMapper.getProductLog(log);
    }
    //删除商品操作日志
    @Override
    public Boolean deleteProductLog(Integer id) {
        return jsProductMapper.deleteProductLog(id);
    }
    //查看商品历史价格详情
    @Override
    public List<JsCourseJournal> getProductPriceLog(JsCourseJournal courseJournal) {
        return jsProductMapper.getProductPriceLog(courseJournal);
    }
    //删除商品
    @Override
    public Boolean deleteProduct(Integer id) {
        return jsProductMapper.deleteProduct(id);
    }
    //删除商品审核
    @Override
    public Boolean deleteProductRecord(Integer id, Integer type) {
        return jsProductMapper.deleteProductRecord(id, type);
    }
    //删除商品评论
    @Override
    public Boolean deleteProductComment(Integer id, Integer type) {
        return jsProductMapper.deleteProductComment(id, type);
    }
    //查询个人商品
    @Override
    public List<JsProduct> getPersonalProduct(JsProduct product) {
        return jsProductMapper.getPersonalProduct(product);
    }
    //添加商品审核
    @Override
    public Boolean addCourseRecord(JsCourseRecord courseRecord) {
        return jsProductMapper.addCourseRecord(courseRecord);
    }
    //添加商品
    @Override
    public Boolean addProduct(JsProduct product) {
        return jsProductMapper.addProduct(product);
    }
    //获取商品编号
    @Override
    public Integer getProductCode(Integer productCode) {
        return jsProductMapper.getProductCode(productCode);
    }
    //获取商品id
    @Override
    public JsProduct getProductId(Integer productCode) {
        return jsProductMapper.getProductId(productCode);
    }

}
